[满分]VC++2008SP1 编写热键注册 模块问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 09:37:47
BOOL BoolRegHotkey;
HWND W_Hwnd;
int ID_HTK;
int OldProc,ScrollProc;
extern "C" _declspec(dllexport) BOOL __stdcall RegHotKey(HWND Hwnd,int ID_HOTKEY,UINT Key)
{
OldProc = SetWindowLong(Hwnd,GWL_WNDPROC,ScrollProc);
if (RegisterHotKey(Hwnd,ID_HOTKEY,MOD_CONTROL|MOD_ALT,Key))
{
W_Hwnd = Hwnd;
BoolRegHotkey = true;
ID_HTK = ID_HOTKEY;
return true;
}
BoolRegHotkey = false;
return false;
}

extern "C" _declspec(dllexport) BOOL __stdcall UnHotKey(HWND Hwnd,int ID_HOTKEY)
{
if (UnregisterHotKey(Hwnd,ID_HOTKEY))
{
return true;
}
return false;
}

LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam)
{
hwnd = W_Hwnd;
switch (BoolRegHotkey)
{
case WM_HOTKEY:if (BoolRegHotkey)
{
ShowWindow(hwnd,SW_HIDE);
}
else
{

帮你改了下:
BOOL BoolRegHotkey;
HWND W_Hwnd;
int ID_HTK;
/*(1)int OldProc,ScrollProc;*/
long OldProc;
HRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

/*(2)extern "C" _declspec(dllexport) BOOL __stdcall RegHotKey(HWND Hwnd,int ID_HOTKEY,UINT Key)*/
__declspec(dllexport) BOOL RegHotKey(HWND Hwnd, int ID_HOTKEY, UINT Key)
{
OldProc = SetWindowLong(Hwnd,GWL_WNDPROC,/*(3)ScrollProc*/(long)WndProc);
if (RegisterHotKey(Hwnd,ID_HOTKEY,MOD_CONTROL|MOD_ALT,Key))
{
W_Hwnd = Hwnd;
BoolRegHotkey = true;
ID_HTK = ID_HOTKEY;
return true;
}
BoolRegHotkey = false;
return false;
}

/*(4)extern "C" _declspec(dllexport) BOOL __stdcall UnHotKey(HWND Hwnd,int ID_HOTKEY)*/
__declspec(dllexport) BOOL UnHotKey(HWND Hwnd, int ID_HOTKEY)
{
if (UnregisterHotKey(Hwnd,ID_HOTKEY))
{
return true;
}
return false;
}
<